﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess
{
    public class ketnoi
    {
        SqlConnection con;

        public string update(string sql)
        {
            string kq = "";
            try
            {

                getConnect();
                SqlCommand cmd = new SqlCommand(sql, con);
                kq = Convert.ToString(cmd.ExecuteNonQuery());
            }
            catch (System.Exception ex)
            {
                kq = "";
            }
            finally
            {
                closeConnect();
            }
            return kq;
        }

        public DataTable getData(string sql)
        {
            DataTable dt = new DataTable();
            try
            {

                getConnect();
                SqlDataAdapter da = new SqlDataAdapter(sql, con);
                da.Fill(dt);
            }
            catch (System.Exception ex)
            {
                dt = null;
            }
            finally
            {
                closeConnect();
            }
            return dt;
        }

        private void getConnect()
        {
            con = new SqlConnection("Data Source=MINHHIEP\\SQLEXPRESS;Initial Catalog=QUANLYDIEM;Integrated Security=True");
            con.Open();
        }
        private void closeConnect()
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }
}
